<template>
	<view v-if="tmpData !== null" class="tn-gradient-bg__cool-6" style="padding-top: 150px;color: #fff;">
		<view class="tn-p-lg" style="position: relative;">
			<view v-if="state === 0" style="font-weight: bold;padding: 10px 0;font-size: large;">绑定用户</view>
			<view v-if="state === 1" style="font-weight: bold;padding: 10px 0;font-size: large;">添加好友</view>
			<view v-if="state === 2" style="font-weight: bold;padding: 10px 0;font-size: large;">个人信息</view>
			<view style="display: flex;align-items: center;">
				<tn-avatar :url="sConf.pics + tmpData.face" style="padding: 5px;" size="xl" shape="circle" shadow
					shadow-color="tn-shadow-lg"></tn-avatar>
				<view>
					<view style="padding: 5px;font-size: large;font-weight: bold;">
						{{ tmpData.nicename }}
					</view>
					<view style="padding: 5px;display: flex;align-items: center;">
						<view style="color: #999;">{{ zipStr(tmpData.phone) }}</view>
						<view style="display: flex;gap: 5px;">
							<tn-bubble-box :options="[{ text: '女性' }]">
								<tn-icon v-if="tmpData.gender == 0" name="girl" size="48"
									color="#ff007f"></tn-icon></tn-bubble-box>
							<tn-bubble-box :options="[{ text: '男性' }]">
								<tn-icon v-if="tmpData.gender == 1" name="boy" size="48"
									color="#007aff"></tn-icon></tn-bubble-box>
							<tn-bubble-box v-if="tmpData.real" :options="[{ text: '个人认证' }]">
								<tn-icon name="identity" size="48" color="#f0ad4e"></tn-icon>
							</tn-bubble-box>
							<tn-bubble-box :options="[{ text: levelData.name }]">
								<tn-icon :name="levelData.icon" size="48" :color="levelData.color"></tn-icon>
							</tn-bubble-box>
							<!-- view class="flashing-light"
								style="width: 4px;height: 4px;position: absolute;top: 12px;right: 12px;"> </view -->
						</view>
					</view>
				</view>
			</view>
			<view class="tn-p-sm tn-flex-center-between">
				<view class="">
					团队规模:{{ tmpData.scope ?? 0 }}
				</view>
				<view class="">
					团队业绩:{{ tmpData.expers.amount ?? 0 }}
				</view>
			</view>
			<view class="tn-p-sm" style="color: #aaa;">
				{{ tmpData.desc }}
			</view>
			<view v-if="state === 0" style="position: absolute;top: 0;right: 0;padding: 15px;" @tap="beBindLastStaff">
				<tn-icon name="my-add" size="60" color="#dd524d"></tn-icon>
				<text>加入团队</text>
			</view>
			<view v-if="state === 1" style="position: absolute;top: 0;right: 0;padding: 15px;" @tap="addChange">
				<tn-icon name="my-add" size="60" color="#dd524d"></tn-icon>
				<text>关注好友</text>
			</view>
		</view>


	</view>
</template>

<script>
import utils from '../../common/utils';
export default {
	name: "friend-staff-pop",
	data() {
		return {
			sConf: getApp().globalData,
			tmpData: null,
			levelData: null,
			state: 0,
		};
	},
	methods: {
		/**
		 * @param {Object} e 目标用户对象
		 * @param {Object} level
		 * @param {Object} state 任务类型 0 绑定；1 关注；2 查看；
		 */
		open(e, level, state) {
			// console.log('staff_ID', e);
			// let host = this.sConf.host + '/weapps/userinfo/' + e + '/';
			// let token = this.sConf.token || ''
			// utils.authenticatorRead(host, token).then((res) => {
			// 	console.log('用户信息', res);
			// 	if (res.rescode === 200) {
			// 		this.tmpData = res.resmsg
			// 	}
			// })
			this.state = state;
			this.levelData = level;
			this.tmpData = e;
		},
		zipStr(e) {
			console.log('zipStr', e);
			return utils.zipStr(e);
		},
		addChange() {
			console.log('addChange');
			if (this.tmpData.id === this.sConf.auth.id) {
				// #ifdef MP-WEIXIN
				wx.vibrateShort();
				// #endif
				uni.showToast({
					icon: 'error',
					title: '不能添加自己'
				})
				return
			}
			let host = this.sConf.host + '/weapps/friend/';
			let token = this.sConf.token || ''
			let data = {
				sid: this.sConf.auth.id,
				pyid: this.tmpData.id
			}
			utils.authenticatorPost(host, token, data).then((res) => {
				console.log('好友请求', res);
				if (res.rescode === 200) {
					this.$emit('addChanged');
				}
			})
		},
		beBindLastStaff() {
			if (this.tmpData.id == this.sConf.auth.id) {
				// #ifdef MP-WEIXIN
				wx.vibrateShort();
				// #endif
				uni.showToast({
					icon: 'error',
					title: '不能添加自己'
				})
				return
			}
			let host = this.sConf.host + '/weapps/bindHelp/';
			let token = this.sConf.token || '';
			let data = {
				sid: this.sConf.auth.id,
				parent: this.tmpData.id
			}
			utils.authenticatorPost(host, token, data).then((res) => {
				console.log('绑定推荐官', res);
				if (res.rescode === 200) {
					uni.redirectTo({
						url: '/pages/login/login'
					})
				}
			})
		}
	}
}
</script>

<style></style>